package scheduler;

import java.util.LinkedList;

import comm.ClientPriority;

import tasks.TaskDescription;

public class TaskScheduler {
	private int numberOfSendTasks = 0;
	private int priority=0;
	private LinkedList<TaskDescription> lastUsedLinkedList = null;
	private long clientID;
	private int position = 0;
	
	public TaskScheduler(LinkedList<TaskDescription> lastUsedLinkedList, int pos) {
		super();
		this.position = pos;
		this.lastUsedLinkedList = lastUsedLinkedList;
		if(lastUsedLinkedList.size()>0){
			synchronized (lastUsedLinkedList) {
				TaskDescription td = lastUsedLinkedList.getFirst();
				this.priority = td.getPriority().ordinal();
				this.clientID = td.getClientID();
			}
		}
	}

	public boolean dispatchSame(){
		if (numberOfSendTasks<=priority && lastUsedLinkedList.size()>0)
			return true;
		else
			return false;


	}
	public int getListHash(){
		return lastUsedLinkedList.hashCode();
	}
	public void addNumberOfSendTasks(){
		numberOfSendTasks++;
	}
	public TaskDescription getTask(){
		numberOfSendTasks++;
		TaskDescription td = null;
		synchronized (lastUsedLinkedList) {
			
		
		td = lastUsedLinkedList.pollFirst();
		
		}
		return td;

	}
	public int getNumberOfSendedTasks() {
		return numberOfSendTasks;
	}

	public LinkedList<TaskDescription> getLastUsedLinkedList() {
		return lastUsedLinkedList;
	}
	public void setLastUsedLinkedList(LinkedList<TaskDescription> lastUsedLinkedList) {
		this.lastUsedLinkedList = lastUsedLinkedList;
	}
	public int getClientPriority() {
		return priority;
	}


	public long getClientID() {
		return clientID;
	}

	public int getPosition() {
		return this.position;
	}

}
